﻿using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RevitAddin
{
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    public class DataForm : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // 获取当前打开的文档
            Document activeDocument = commandData.Application.ActiveUIDocument.Document;
            // 获取文档的文件名（不包含路径和扩展名）
            string fileName = activeDocument.Title;

            // 确保文件名有效（替换非法字符）
            fileName = fileName.Replace(":", "_").Replace("\\", "_").Replace("/", "_");

            Global.ModelName = fileName;

            CableDataForm form = new CableDataForm();
            form.Show();
            return Result.Succeeded;
        }
    }
}
